import { getRandomAnimals } from "@/service/main/main"
import { defineStore } from "pinia"

interface IMainState {
  randomAnimals: any[]
}

const useMainStore = defineStore("main", {
  state: (): IMainState => ({
    randomAnimals: []
  }),
  actions: {
    // 登录和刷新时设置执行了这个函数，拿到下拉的数据
    async getRandomAnimalsAction(quantity: number) {
      const result = await getRandomAnimals(quantity)
      //   console.log(result)
      if (result.data.code == 200) {
        this.randomAnimals = result.data.data
      } else {
        console.log(result.data.message)
        return Promise.reject(result.data.message)
      }
    }
  }
})

export default useMainStore
